'use strict';

var zlqiniu ={
    'setUp':function (args) {
        var domain = args['domain'];
        var params ={
            browse_button:args['browse_btn'],
            runtimes:'html5,flash,html4',//长传模式一次退化
            max_file_size:'500mb',//文件最大允许尺寸
            dragdrop:false,//是否开启拖曳功能
            chunk_size:'4mb',//分块上传时,每片的大小
            uptoken_url:args['uptoken_url'],//ajax请求token的url
            domain:domain,//图片下载时候的域名
            get_new_uptoken:false,//是否每次上传都要从业务服务器获取token
            auto_start:true,//如果设置了true,只要选择了图片,就会自动上传
            unique_names:true,
            multi_selection:false,
            filters:{
              mime_types:[
                  {title:'Image files',extensions:'jpg,gif,png'},
                  {title:'Video files',extensions:'flv,mpg,mpeg,avi,wmv,mov,asf,rm,rmvb,mkv,m4v,mp4'}
              ]
            },
            log_level:5,//log级别
            init:{
                'FileUpLoaded':function (up, file, info) {
                    if (args['success']) {
                        var success = args['success'];
                        file.name = domain+file.target_name;
                        success(up,file,info);
                    }
                },
                'Error':function (up, err, errTip) {
                    if (args['error']){
                        var error = args['error'];
                        error(up,err,errTip);
                    }
                },
                'UploadProgress':function (up, file) {
                    if (args['progress']) {
                        args['progress'](up, file);
                    }

                },
                 'FilesAdded':function (up, files) {
                    if (args['fileadded']) {
                        args['fileadded'](up, files);
                    }

                },
                'UploadComplete':function () {
                    if (args['complete']){
                        args['complete']();
                    }
                }


            },
        };
        //把args中的参数放到paramszhongqu
        for(var key in args){
            params[key] = args[key];

        }

        var uploader = Qiniu.uploader(params);
        return uploader;
    }
};